package com.yz.house.ui.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.yz.house.R;
import com.yz.house.base.BaseFragment;
import com.yz.house.func.ListDecoration;
import com.yz.house.model.ContentBean;
import com.yz.house.ui.activity.ContentDetailActivity;
import com.yz.house.ui.adaper.ContentListAdapter;
import com.yz.house.ui.adaper.HouseHelpAdapter;
import com.yz.house.ui.utils.ContentUtils;
import com.yz.house.ui.utils.SizeUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Demo
 *
 * @author zhangyf
 * @date 2018/4/13 0013.
 */
public class ContentListFragment extends BaseFragment {

    @BindView(R.id.rv_content)
    RecyclerView rv_content;
    ContentListAdapter adapter;
    private String title;

    public static ContentListFragment newInstance(String title) {
        ContentListFragment fragment = new ContentListFragment();
        Bundle args = new Bundle();
        args.putString("title",title);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void onInitLazyData() {
        title = getArguments().getString("title");
    }

    @Override
    protected void onInitFastData() {
        title = (String) getArguments().get("title");
    }

    @Override
    protected void onInitFastView() {
        switch (title) {
            case "推荐":
                adapter = new ContentListAdapter(ContentUtils.getHomeList(1));
                break;
            case "客厅":
                adapter = new ContentListAdapter(ContentUtils.getHomeList(2));
                break;
            case "卧室":
                adapter = new ContentListAdapter(ContentUtils.getHomeList(3));
                break;
            case "厨房":
                adapter = new ContentListAdapter(ContentUtils.getHomeList(4));
                break;
            case "卫生间":
                adapter = new ContentListAdapter(ContentUtils.getHomeList(5));
                break;
            case "餐厅":
                adapter = new ContentListAdapter(ContentUtils.getHomeList(6));
                break;
        }
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseAdapter, View view, int position) {
                Bundle bundle = new Bundle();
                bundle.putString("img",adapter.getData().get(position).getCover());
                bundle.putString("content",adapter.getData().get(position).getContent());
                mActivity.readyGo(ContentDetailActivity.class,bundle);
            }
        });
        rv_content.setLayoutManager(new LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL,false));
        rv_content.setAdapter(adapter);
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fragment_content_list;
    }

}
